<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>大象与猩猩 | 找回密码</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="assets/css/amazeui.min.css">
</head>
<body>
	<div class="am-u-sm-center">
		<h2>用户.找回密码</h2>
		<hr />
	</div>
	<div class="am-g">
		<div class="am-u-sm-12">
			<form id="submitForm" class="pure-form pure-form-aligned am-u-sm-12">
				<div class="am-g">
					<div class="am-u-sm-12 am-form-group am-form-icon">
						<i class="am-icon-user am-padding-left-sm"></i><input required="required" maxlength="11" placeholder="请输入手机号" id="phone" name="phone" type="tel" class="am-form-field am-input-sm">
					</div>
				</div>
				<div class="am-g">
					<div class="am-u-sm-8 am-form-group am-form-icon">
						<input id="code" name="code" required="required" placeholder="请输入验证码" type="text" class="am-form-field am-input-sm">
					</div>
					<div class="am-u-sm-4" style="padding: inherit;">
						<button id="send" class="am-btn am-btn-sm" onclick="sendCode()">获取验证码</button>
					</div>
				</div>
				<div class="am-g">
					<div class="am-u-sm-12 am-form-group am-form-icon">
						<i class="am-icon-lock am-padding-left-sm"></i><input id="password1" onchange="checkPasswords()" required="required" name="password" placeholder="请输入密码" type="password" class="am-form-field am-input-sm">
					</div>
				</div>
				<div class="am-g">
					<div class="am-u-sm-12 am-form-group am-form-icon">
						<i class="am-icon-lock am-padding-left-sm"></i><input id="password2" onchange="checkPasswords()" required="required" name="password2" placeholder="请再输入一次" type="password" class="am-form-field am-input-sm">
					</div>
				</div>
				<div class="am-g">
					<div class="am-u-sm-12">
						<input id="verify" value="确定" id="send" class="am-btn am-btn-primary" type="submit">
					</div>
				</div>
			</form>
		</div>
	</div>

	<script src="assets/js/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript">
		function sendCode() {
			event.preventDefault();

			var phone = $("#phone").val();
			if (phone == "") {
				alert("请输入手机号！");
				return;
			}
			$.ajax({
				type : "POST",
				url : "../sms/send",
				data : $.param({
					"phone" : phone,
					"type" : "Getback"
				}),
				dataType : "json",
				success : function(data) {

					if (data.code == 0) {
						alert(data.info);
					} else {

						/* 	$("#verify").attr("disabled", false);
							$("#send").attr("disabled", true); */
						alert(data.info);
					}
				},
				error : function(data) {
				}
			});
		}

		function checkPasswords() {
			var pass1 = document.getElementById("password1");
			var pass2 = document.getElementById("password2");

			if (pass1.value != pass2.value) {
				pass1.setCustomValidity("两次输入的密码不匹配");
			} else
				pass1.setCustomValidity("");
		}

		$("#submitForm").submit(function submitPWD() {
			event.preventDefault();

			$.ajax({
				type : "GET",
				url : "../encryption/transfer?plain=" + $('#password1').val(),
				success : function(data) {
					if (data.code == 1) {
						$('#password1').val(data.object);
						$('#password2').val(data.object);
						$.ajax({
							type : "POST",
							url : "../sms/getback",
							data : $("#submitForm").serialize(),
							success : function(data) {
								console.log(data);
								if (data.code == 1) {
									alert("成功找回密码！");
									window.location.href = "wechat-login.html";
								} else {
									alert(data.info);
									$('#password1').val('');
									$('#password2').val('');
								}
							},
							error : function(data) {
							}
						});
					} else {
						alert(data.info);
					}
				},
				error : function(data) {
				}
			});

		});
	</script>
</body>
</html>